<template>
  <!-- 老虎机游戏记录 -->
  <div class="app-container">
    <div class="app-wrap">
      <search-table ref="table" :table-loading="listLoading" :table-data="dataList" @query="getDataList(true)" @reset="refresh">
        <template v-slot:row>
          <el-form-item label="渠道:" label-width="50px">
            <el-select v-model="listQuery.agent_id" placeholder="请选择渠道" filterable >
              <el-option label="全部" value="" ></el-option>
              <el-option :label="'【'+item.value+'】'+item.label" :value="item.value" v-for="(item, index) in channelData" :key="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item  label="日期时间:" label-width="75px">
            <el-date-picker is-range v-model="listQuery.dateTime" type="daterange" range-separator="至" start-placeholder="开始日期" 
            end-placeholder="结束日期" class="full-width-input time-box" :default-time="['00:00:00', '23:59:59']" :clearable="false"></el-date-picker>
          </el-form-item>
          <el-form-item label="玩家ID:" label-width="60px">
            <el-input type="number" v-model="listQuery.user_id" clearable placeholder="请输入玩家ID"/>
          </el-form-item>
          <el-form-item label="账户类型:" label-width="75px">
            <el-select v-model="listQuery.is_test_account" placeholder="请选择账户类型" filterable >
              <el-option label="全部" :value="0" ></el-option>
              <el-option label="测试账户" :value="1" ></el-option>
              <el-option label="普通账户" :value="2" ></el-option>
            </el-select>
          </el-form-item>
        </template>
        <template v-slot:actions>
          <div class="statistic flex">
            <el-button type="info" size="mini" icon="el-icon-refresh" @click="getDataList">刷新</el-button>
            <el-button class="marginL20 marginR20" type="success" size="mini" icon="el-icon-wallet" @click="isShowTotalsDetails=!isShowTotalsDetails,getSummyDataList()">统计</el-button>
            <div class="flex" v-show="isShowTotalsDetails" style="height:36px">
              <p> 玩家下注金额：<span class="colorGre">{{ totalForm.bet_amount }}</span></p>
              <p> 玩家中奖金额：<span class="colorGre">{{ totalForm.game_income }}</span></p>
              <p> 玩家输赢：<span :class="totalForm.user_income>0?'colorGre':'colorRed'">{{ totalForm.user_income }}</span></p>
            </div>
          </div>
        </template>
        <template>
          <el-table-column prop="agent_id" label="渠道名" align="center" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-show="scope.row.agent_id">【{{scope.row.agent_id}}】{{ $public.channelLabel(scope.row.agent_id) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="user_id" label="用户ID" align="center" width="120"/>
          <el-table-column prop="nick_name" label="用户昵称" align="center" width="150" show-overflow-tooltip/>
          <el-table-column prop="account_type" label="账户类型" align="center" width="120">
            <template slot-scope="scope">
              <el-tag :type="accountTag(scope.row.account_type)">{{ accountType(scope.row.account_type)}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="time_str" label="日期时间" align="center" width="120"/>
          <el-table-column prop="bet_amount" label="下注金额" align="center" width="150"/>
          <el-table-column prop="game_income" label="中奖金额" align="center" width="120"/>
          <el-table-column prop="game_num" label="下注次数" align="center" width="100"/>
          <el-table-column prop="mini_num" label="小奖次数" align="center" width="100"/>
          <el-table-column prop="minor_num" label="中等奖次数" align="center" width="100"/>
          <el-table-column prop="major_num" label="大奖次数" align="center" width="100"/>
          <el-table-column prop="grand_num" label="超大奖次数" align="center" width="100"/>
          <el-table-column prop="free_game_num" label="免费游戏次数" align="center" width="120"/>
          <el-table-column prop="jackpot_num" label="jackpot触发次数" align="center" width="140"/>
          <el-table-column prop="bonus_num" label="金库游戏触发次数" align="center" width="140"/>
          <el-table-column prop="five_multiple" label="0-5倍中奖次数" align="center" width="120"/>
          <el-table-column prop="ten_multiple" label="5-10倍中奖次数" align="center" width="120"/>
          <el-table-column prop="twenty_five_multiple" label="10-25次数" align="center" width="120"/>
          <el-table-column prop="fifty_five_multiple" label="25-55次数" align="center" width="120"/>
          <el-table-column prop="hundred_multiple" label="55-100次数" align="center" width="120"/>
          <el-table-column prop="over_multiple" label="100以上中奖次数" align="center" width="150"/>
        </template>
        <template v-slot:footer>
          <pagination :total="currentTotal" :page.sync="listQuery.page" :limit.sync="listQuery.size" @pagination="getDataList" />
        </template>
      </search-table>
    </div>
  </div>
</template>

<script>
import {
  throttle
} from '@/utils/index'
import {
  getSlotRecords,
  getSlotSummy
} from '@/api/statistics'
import {
  ACCOUNT_TYPE
} from '@/utils/enum'
import SearchTable from '@/components/SearchTable'
export default {
  name: 'slotStatistics',
  components: {
    SearchTable
  },
  data () {
    return {
      ACCOUNT_TYPE,
      channelData: this.$store.state.commonState.channelDataArray,
      listQuery: {
        page: 1,
        size: 50,
        agent_id:'',
        user_id:'',
        is_test_account:0,
        dateTime:[this.$public.getDateDay(0)+' 00:00:00',this.$public.getDateDay(0)+' 23:59:59'],
        start_time: '',
        end_time: '',
      },
      listLoading: true,
      dataList: [],
      currentTotal: 0,
      isShowTotalsDetails: false,
      totalForm:{
        bet_amount: '',// 玩家下注金额
        game_income: '',// 玩家中奖金额
        user_income: '',// 玩家输赢
      },
    }
  },
  created () {},
  activated(){
    this.channelData=this.$store.state.commonState.channelDataArray
    this.getDataList();
    this.getSummyDataList();
  },
  methods: {
    // 老虎机游戏记录
    async getDataList (query) {
      let that = this,params=that.listQuery;
      if(query && !query.page){
        params.page=1
        params.size=50
      }
      that.dataList = []
      if (params.dateTime && params.dateTime[0] && params.dateTime[1]) {
        params.start_time = that.$public.standardDate(params.dateTime[0])
        params.end_time = that.$public.standardDate(params.dateTime[1])
      }
      const response = await getSlotRecords(params)
      if (response.code == 1) {
        if (response.data.list) {
          response.data.list.forEach(item=>{
            item.time=that.$public.standardDate(item.time)
            item.bet_amount=that.$public.mathNumberDivideWan(item.bet_amount)
            item.game_income=that.$public.mathNumberDivideWan(item.game_income)
          })
          that.dataList = response.data.list
          that.currentTotal = response.data.total
        }
      }else{
        that.$message.error(response.msg)
      }
      that.listLoading = false
    },
    // 汇总
    async getSummyDataList () {
      let that = this,params=that.listQuery;
      if(!that.isShowTotalsDetails) return
      if (params.dateTime && params.dateTime[0] && params.dateTime[1]) {
        params.start_time = that.$public.standardDate(params.dateTime[0])
        params.end_time = that.$public.standardDate(params.dateTime[1])
      }
      const response = await getSlotSummy(params)
      if (response.code == 1) {
        if (response.data) {
          that.totalForm.bet_amount=that.$public.mathNumberDivideWan(response.data.bet_amount)
          that.totalForm.game_income=that.$public.mathNumberDivideWan(response.data.game_income)
          that.totalForm.user_income=that.$public.mathNumberDivideWan(response.data.user_income)
        }
      }else{
        that.$message.error(response.msg)
      }
    },
    // 账号类型展示
    accountType(cellValue){
      return (this.ACCOUNT_TYPE.find((item) => item.value === cellValue)?.label || "测试账号");
    },
    // 账号类型展示
    accountTag(cellValue){
      return (this.ACCOUNT_TYPE.find((item) => item.value === cellValue)?.type || "-");
    },
    // 刷新
    refresh: throttle(function () {
      this.listQuery = {
        page: 1,
        size: 50,
        agent_id:'',
        user_id:'',
        is_test_account:0,
        dateTime:[this.$public.getDateDay(0)+' 00:00:00',this.$public.getDateDay(0)+' 23:59:59'],
        start_time: '',
        end_time: '',
      }
      this.getDataList()
    }, 2000),
  }
}
</script>

<style lang="scss" scoped>

</style>
